<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('部分收货')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <input type="hidden" th:value="${id}" id="kid">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal add-btn1">
                        <i class="layui-icon">&#x1005;</i> 操作人员
                    </a>
                    <!--<a class="layui-btn layui-btn-sm layui-btn-normal print-btn">
                        <i class="layui-icon">&#x1005;</i> 打印托盘码
                    </a>-->
                    <a class="layui-btn layui-btn-sm layui-btn-normal edit-btn1">
                        <i class="layui-icon">&#x1005;</i> 确认收货
                    </a>
                    <!-- Single button -->
                    <!-- <div class="btn-group">
                         <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                 aria-haspopup="true" aria-expanded="false">
                             多选操作 <span class="caret"></span>
                         </button>
                         <ul class="dropdown-menu">
                             <li><a id="btn_jin" href="#">禁用</a></li>
                             <li><a id="btn_qi" href="#">启用</a></li>
                         </ul>
                     </div>-->
                </div>
                <input id="xssl" type="hidden">
                <input id="pssl" type="hidden">
                <input id="czry" type="hidden">
                <input id="jssl" type="hidden">
                <input id="jsyy" type="hidden">
                <input id="pid" type="hidden">
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table2" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

<!--多选操作人员-->
<div style="padding: 0px 15px;" hidden="hidden" id="addfunction">
    <div class="layui-fluid larry-wrapper" >
        <div class="layui-card">
            <form class="layui-form layui-card-header  layui-card-header-auto" id="tiaozhengForm">
                <div class="layui-inline">
                    <label class="layui-form-label">操作人员</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="czren" name="czren"  />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<script>

    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent1 = {

            "click #btn_tz2": function (e, value, row, index) {//调整
                save(row.id, index);
            },
            "click #btn_print": function (e, value, row, index) {//打印
                btn_print(row.id);
            }
        }
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;

        //调整
        function save(id, index) {
            var url, dialog = zzpUtils.dialogBtn;
            dialog.init({
                title: "收货调整",
                id: "shtz",
                type: 2,
                isForm: true,
                subBtn: 'form1btn',
                area: ['70%', '70%'],
                url: "/AsnCollect/Asntz?id=" + id,
                beforSubmit: function (iframe) {
                    dialog.form = $("#form1", iframe.document);
                },
                end: function (data) {
                    var xssl = $("#xssl").val();//现收数量
                    var czry = $("#czry").val();//操作人员
                    var pssl = $("#pssl").val();//破损数量
                    var jssl = $("#jssl").val();//拒收数量
                    var jsyy = $("#jsyy").val();//拒收原因
                    var pd=$("#pid").val();
                    if(pd==1){
                        var formObject = {};
                        var row = formObject;
                        row.czry = czry;//操作人员
                        row.xssl = xssl;//现收数量
                        row.jsyy = jsyy;//拒收原因
                        row.pssl = pssl;//破损数量
                        row.jssl = jssl//拒收数量
                        $table.bootstrapTable('updateRow', {index: index, row: row});
                        $("#pid").val(0);
                    }
                }
            });
        }
        /*打印托盘码*/
        function btn_print(id){
            var ids=[];
            ids.push(id);
            zzpUtils.confirm("您将打印码盘信息", function (index) {
                zzpUtils.action({
                    url: "/wmspalletsorting/baseDyid" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        if(data.title=='码盘明细打印失败'){
                            setTimeout(function () {
                                layer.msg(data.message);
                            }, 500);
                        }else{
                            var LODOP=getLodop();
                            LODOP.PRINT_INIT('打印码盘信息');
                            for(var i=0;i<data.rows.length;i++){
                                var oDate = new Date(); //实例一个时间对象；
                                var time=oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate()+' '+oDate.getHours()+':'+oDate.getMinutes()+':'+oDate.getSeconds();
                                LODOP.ADD_PRINT_TEXT(28,34,270,30,time);
                                LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                                LODOP.ADD_PRINT_BARCODE(48,34,270,47,"EAN128B",data.rows[i].asnbh);
                                LODOP.ADD_PRINT_TEXT(110,34,100,30,"货品编号");
                                LODOP.ADD_PRINT_TEXT(110,100,307,30,data.rows[i].bh);
                                LODOP.ADD_PRINT_TEXT(140,34,100,30,"货品名称");
                                LODOP.ADD_PRINT_TEXT(140,100,307,30,data.rows[i].mc);
                                LODOP.ADD_PRINT_TEXT(170,34,100,30,"供应商");
                                LODOP.ADD_PRINT_TEXT(170,100,307,30,data.rows[i].gys);
                                LODOP.ADD_PRINT_TEXT(200,34,100,30,"生产日期");
                                LODOP.ADD_PRINT_TEXT(200,100,307,30,data.rows[i].scrq);
                                LODOP.ADD_PRINT_BARCODE(210,180,190,40,"EAN128B",data.rows[i].lpn);
                                LODOP.ADD_PRINT_TEXT(255,34,307,30,"货品批号");
                                LODOP.ADD_PRINT_TEXT(255,100,307,30,data.rows[i].hppc);
                                if(i>=0){
                                    LODOP.NewPage();//分页
                                }
                            }
                        }
                        LODOP.PREVIEW();
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }

        var $table = zzpUtils.table({
            elem: '#table2',
            isApi: true,
            uniqueId:"id",
            pagination: true,
            queryParams :queryParams1,
            url: '/wmsEstimatedArrivalOrderDetailed/seackASNSorting',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'hpbh',
                title: '货品编号'
            }, {
                field: 'hpmc',
                title: '货品名称'
            }, {
                field: 'kwmc',
                title: '收货库位'
            }, {
                field: 'hppc',
                title: '货品批次'
            }, {
                field: 'scrq',
                title: '生产日期'
            }, {
                field: 'yqsl',
                title: '预期数量'
            }, {
                field: 'xssl',
                title: '现收数量'
            }, {
                field: 'gg',
                title: '规格'
            }, {
                field: 'czry',
                title: '操作人员'
            }, {
                field: 'pssl',
                title: '破损数量'
            }, {
                field: 'jssl',
                title: '拒收数量'
            }, {
                field: 'jsyy',
                title: '拒收原因'
            }, {
                field: 'sdsl',
                title: '实到数量'
            }, {
                field: 'show_asnzt',
                title: 'ASN状态'
            }, {
                field: 'caozuo',
                title: '操作',
                events: operateEvent1,
                formatter: operateFormatter1
            }],
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }
        });

        //得到查询的参数
        function queryParams1(params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                ssyqdid: $("#kid").val()
            };
            return temp;
        }

        /*表格右侧按钮*/
        function operateFormatter1(value, row, index) {

            return [
                '<a class="layui-btn layui-btn-xs" id="btn_tz2">调整</a>',
                /*'<a class="layui-btn layui-btn-xs" id="btn_print">打印托盘码</a>'*/
            ].join('')
        }

        /*顶部按钮多选操作人员*/
        $(".add-btn1").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length > 0) {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                layer.open({
                    type: 1,
                    title: "生成操作人员",
                    content: $("#addfunction"),
                    area:['350px','260px'],
                    btn:['保存','取消'],
                    btn1: function(index, layero){
                        var pass = {};
                        pass.czry =$('#czren').val() ;//操作人员
                        for(var i=0;i<ids.length;i++){
                            $table.bootstrapTable('updateByUniqueId', {id: ids[i], row: pass});
                        }
                        $('#czren').val('') ;
                        layer.close(index);
                    }
                    ,btn2 : function (index, layero) {
                        layer.close(index);
                    }
                })

            } else {
                layer.msg("请选择一条进行编辑");
            }
        })
        /*顶部按钮打印托盘码*/
        $(".print-btn").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length > 0) {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                zzpUtils.confirm("您将打印码盘信息", function (index) {
                    zzpUtils.action({
                        url: "/wmspalletsorting/baseDyid" ,
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {
                            if(data.title=='码盘明细打印失败'){
                                setTimeout(function () {
                                    layer.msg(data.message);
                                }, 500);
                            }else{
                                var LODOP=getLodop();
                                LODOP.PRINT_INIT('打印码盘信息');
                                for(var i=0;i<data.rows.length;i++){
                                    var oDate = new Date(); //实例一个时间对象；
                                    var time=oDate.getFullYear()+'-'+(oDate.getMonth()+1)+'-'+oDate.getDate()+' '+oDate.getHours()+':'+oDate.getMinutes()+':'+oDate.getSeconds();
                                    LODOP.ADD_PRINT_TEXT(28,34,270,30,time);
                                    LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                                    LODOP.ADD_PRINT_BARCODE(48,34,270,47,"EAN128B",data.rows[i].asnbh);
                                    LODOP.ADD_PRINT_TEXT(110,34,100,30,"货品编号");
                                    LODOP.ADD_PRINT_TEXT(110,100,307,30,data.rows[i].hpbh);
                                    LODOP.ADD_PRINT_TEXT(140,34,100,30,"货品名称");
                                    LODOP.ADD_PRINT_TEXT(140,100,307,30,data.rows[i].hpmc);
                                    LODOP.ADD_PRINT_TEXT(170,34,100,30,"供应商");
                                    LODOP.ADD_PRINT_TEXT(170,100,307,30,data.rows[i].gys);
                                    LODOP.ADD_PRINT_TEXT(200,34,100,30,"生产日期");
                                    LODOP.ADD_PRINT_TEXT(200,100,307,30,data.rows[i].scrq);
                                    LODOP.ADD_PRINT_BARCODE(210,180,190,40,"EAN128B",data.rows[i].lpn);
                                    LODOP.ADD_PRINT_TEXT(255,34,307,30,"货品批号");
                                    LODOP.ADD_PRINT_TEXT(255,100,307,30,data.rows[i].hppc);
                                    if(i>=0){
                                        LODOP.NewPage();//分页
                                    }
                                }
                            }
                            LODOP.PREVIEW();
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
            } else {
                layer.msg("请选择一条进行打印");
            }
        })

        /*顶部按钮确认收货  */
        $(".edit-btn1").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            console.log($rows);
            var number=0;
            if ($rows.length > 0) {
                for (var i=0;i<$rows.length;i++){
                    if ($rows[i].czry==''){
                        number++;
                    }
                }
                if(number>0){
                    layer.msg("您选中的信息有未调整的，请先调整！！！");
                }else{
                    zzpUtils.confirm("是否确定收货", function (index) {
                        zzpUtils.action({
                            url: "/wmsreceiving/ASNreceiving/"+$("#kid").val(),
                            data: JSON.stringify($rows),
                            success: function (data) {
                                setTimeout(function () {
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index); //再执行关闭
                                    top.layer.msg(data.title);
                                }, 500);
                                // zzpUtils.refreshTable("#table");
                            }, error: function (xhr, textStatus) {
                                console.log(textStatus);
                                console.log(xhr)
                            }
                        })
                    })
                    return false;

                }

            } else {
                layer.msg("请选择一条进行操作");
            }
        })
    });

</script>
</html>